package cn.xpf.study.dao;

import cn.xpf.study.model.LessonItem;
import cn.xpf.study.model.LessonVideo;
import java.util.List;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * Create on 2021/5/13
 *
 * @author shuxinsheng@qiyi.com
 **/
@Mapper
public interface LessonVideoMapper {

    String table = "lesson_video";

    @Select("select * from " + table + " where lessonId=#{lessonId} and `deleted` != 1 order by `order` asc")
    List<LessonVideo> findAllByLessonId(@Param("lessonId") int lessonId);

    @Select("select * from " + table + " where id=#{id}")
    LessonVideo findOneById(@Param("id") int id);

    @Update("update " + table + " set `order`=#{lessonVideo.order},`title`=#{lessonVideo.title},`url`=#{lessonVideo.url} where id=#{lessonVideo.id}")
    void updateOne(@Param("lessonVideo") LessonVideo lessonVideo);

    @Insert("insert into " + table + "(`lessonId`,`order`, `title`, `url`) values (#{lessonVideo.lessonId},#{lessonVideo.order},#{lessonVideo.title},#{lessonVideo.url})")
    void insertOne(@Param("lessonVideo") LessonVideo lessonVideo);

    @Update("update " + table + " set `deleted`=1 where id=#{videoId}")
    void deleteOne(@Param("videoId") int videoId);

}
